<?php

class Model_Archive extends Model
{
	public function get_data()
	{	
		//array to store photo information with keys
		$arraypush = array();
		
		//connection method
		$link=$this->connect_to_db();

		// Paginator values calculate
		$max_id_q = mysqli_query($link, "select max(id) from photos_list; ");
		$max_id = mysqli_fetch_array($max_id_q,  MYSQLI_ASSOC);

		$step = 80;

		/* calc number of all pages for paginator
			- $skip: number of current page
			- $step: number of photos per one page
			- $number_of_pages: calc number of all pages */

		if(isset($_GET['skip']))
			$skip=((int)$_GET['skip'] - 1) * $step;
		else $skip=0;

		
		if($max_id['max(id)'] % $step == 0)
			$number_of_pages=intval($max_id['max(id)'] / $step) ;
		else
			$number_of_pages = intval($max_id['max(id)'] / $step) +1;

		//select photos and tags

		$skip_q = mysqli_query($link, "select * from photos_list order by id desc limit $skip, $step;");

		while($skip_photo = mysqli_fetch_array($skip_q, MYSQLI_ASSOC))
			array_push($arraypush, 
						array(
						'Id' => $skip_photo['id'],
						'Page' => $skip_photo['page_number'],
						'Photo' => $skip_photo['photo_filename']
						)
				);

		$arraypaginator = array(
			'NumOfPages' => $number_of_pages,
			'Step' => $skip/$step+1);

		mysqli_close($link);
		
		return array($arraypush, $arraypaginator);
	}

}
